package com.cskaoyan.jdbc;

import com.cskaoyan.jdbc.util.JdbcUtil;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @ClassName CUDJdbc
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2023/2/6 17:14
 * @Version V1.0
 **/
public class RJdbc {

    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            connection = JdbcUtil.getConnection();
            statement = connection.createStatement();
            resultSet = statement.executeQuery("select * from customer");
            while (resultSet.next()){
                String name = resultSet.getString("name");
                String city = resultSet.getString("city");
                System.out.println(name + " " + city);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                JdbcUtil.release(connection, statement, resultSet);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}
